from toee import *
import _include
from co8Util.TimedEvent import *
from scripts import *


def san_dialog( attachee, triggerer ):
	attachee.turn_towards(triggerer)
	if (game.quests[101].state == qs_completed or game.quests[101].state == qs_botched):
		triggerer.begin_dialog( attachee, 600 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def san_heartbeat( attachee, triggerer ):
	if (game.global_flags[875] == 1 and game.global_flags[876] == 0 and game.quests[101].state != qs_completed and not anyone( triggerer.group_list(), "has_item", 12900 )):
		game.global_flags[876] = 1
		game.timevent_add( amii_dies, (), 140000000 )
	if (game.quests[101].state == qs_completed and attachee.map == 5022 and game.global_flags[861] == 0):
		amii = game.obj_create( 14501, location_from_axis (475L, 480L) )
		game.global_flags[861] = 1
	if (game.quests[101].state == qs_completed and attachee.map == 5001 and game.global_flags[864] == 0):
		game.global_flags[864] = 1
		amii = game.obj_create( 14501, location_from_axis (728L, 387L) )
	return RUN_DEFAULT

def amii_dies():
	game.quests[101].state = qs_botched
	return RUN_DEFAULT

def letter_written():
	game.global_vars[767] = 2
	timedEventAdd(give_reward, (), 76)
	return RUN_DEFAULT

def give_reward():
	game.global_vars[767] = 3
	return RUN_DEFAULT

def order_item():
	game.global_vars[769] = 1
	timedEventAdd(item_arrived, (), 409)
	return RUN_DEFAULT

def item_arrived():
	game.global_vars[769] = 2
	return RUN_DEFAULT

def give_item(pc):
	game.global_vars[769] = 0
	item = game.global_vars[768]
	create_item_in_inventory(item,pc)
	game.global_vars[768] = 0
	game.global_vars[776] = game.global_vars[776] + 1
	return RUN_DEFAULT
